//
//  STGuidanceViewController.swift
//  SeaTransportManage
//
//  Created by guopengwen on 2021/11/26.
//

import UIKit
 
class STGuidanceViewController: GPBaseViewController, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {

    override func viewDidLoad() {
        super.viewDidLoad()
        setNavBarTitle("流程指引")
        addSubviewForPage()
    }

    func addSubviewForPage() {
        addTopBGView()
        
        view.addSubview(collectionView)
        collectionView.snp.makeConstraints { (make) in
            make.top.equalTo(20)
            make.left.equalTo(16)
            make.right.equalTo(-16)
            make.bottom.equalTo(0)
        }
        
        STGuidanceCollectionViewCell.registerTo(collectionView)
    }

    
    // UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout
    func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 1
    }

    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 4
    }

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        let h = 208 * (kScreenWidth - 48) / 327
        return CGSize.init(width: (kScreenWidth - 48) / 2.0, height: h)
    }

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = STGuidanceCollectionViewCell.reusableCell(collectionView, indexPath: indexPath)
        cell?.updateCellData(boxType: indexPath.item)
        return cell ?? collectionView.dequeueReusableCell(withReuseIdentifier: STGuidanceCollectionViewCell.identifier, for: indexPath)
    }

    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        switch indexPath.item {
            case 0:
                let entryProcessVC: STEntryProcessViewController = STEntryProcessViewController.init()
                navigationController?.pushViewController(entryProcessVC, animated: true)
                break
            case 1:
                let suitcaseVC: STSuitcaseViewController = STSuitcaseViewController.init()
                navigationController?.pushViewController(suitcaseVC, animated: true)
                break
            case 2:
                let enchaseVC: STEnchaseViewController = STEnchaseViewController.init()
                navigationController?.pushViewController(enchaseVC, animated: true)
                break
            case 3:
                let customerServiceVC: STCustomerServiceViewController = STCustomerServiceViewController.init()
                navigationController?.pushViewController(customerServiceVC, animated: true)
                break
            default: break
        }
    }
    
    // 懒加载
    lazy var collectionView: UICollectionView = {
        let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout.init()
        layout.minimumLineSpacing = 16
        layout.minimumInteritemSpacing = 0
        let collectView: UICollectionView = UICollectionView.init(frame: CGRect.zero, collectionViewLayout: layout)
        collectView.delegate = self
        collectView.dataSource = self
        collectView.backgroundColor = UIColor.init(hexString: "#FFFFFF", alpha:0)
        return collectView
    }()
}
